﻿using System;

namespace iTPS.Service.Core.Service
{
    public static class ServiceExtensions
    {
        public static IServiceHostConfiguration Service<T>(this IServiceHostConfiguration serviceHostConfiguration) where T : class, IService, new()
        {
            serviceHostConfiguration.ServiceInstance = new T();
            return serviceHostConfiguration;
        }

        public static IServiceHostConfiguration OnException<T>(this IServiceHostConfiguration serviceHostConfiguration, Action<Exception> exceptionHandler)
        {
            serviceHostConfiguration.OnExceptionHandler = exceptionHandler;
            return serviceHostConfiguration;
        }

        public static IServiceHostConfiguration OnExit<T>(this IServiceHostConfiguration serviceHostConfiguration, Action<IService> exitHandler)
        {
            serviceHostConfiguration.OnExitHandler = exitHandler;
            return serviceHostConfiguration;
        }
    }
}
